﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class PlatForm_More : System.Web.UI.Page
{
	private List<PX.Question.Entity> listQuestions = new List<PX.Question.Entity>();
	/// <summary>
	/// 问题控制类
	/// </summary>
	/// <![CDATA[2014-7-23 17:03:17]]>
	private PX.Question.Component clsQuestionComp = new PX.Question.Component();

	protected void Page_Load(object sender, EventArgs e)
	{
		if (!IsPostBack)
		{
			BindControls();
		}
	}

	protected override void OnInit(EventArgs e)
	{
		base.OnInit(e);

		LBtnFirst.Click += new EventHandler(LBtnFirst_Click);
		LBtnForward.Click += new EventHandler(LBtnForward_Click);
		LBtnNext.Click += new EventHandler(LBtnNext_Click);
		LBtnLast.Click += new EventHandler(LBtnLast_Click);
		Grv.DataBound += new EventHandler(Grv_DataBound);
		Grv.RowDataBound += new GridViewRowEventHandler(Grv_RowDataBound);
	}

	void Grv_RowDataBound(object sender, GridViewRowEventArgs e)
	{
		if (e.Row.RowIndex >= 0)
		{
			for (int i = 0; i < e.Row.Cells.Count; i++)
			{
				HyperLink hLink = new HyperLink();

				hLink.Text = e.Row.Cells[i].Text;
				hLink.Target = "_blank";
				hLink.NavigateUrl = "QuestionDetail.aspx?QuestionID=" + Grv.DataKeys[e.Row.RowIndex].Value.ToString();

				e.Row.Cells[i].Controls.Add(hLink);
			}
		}
	}

	void Grv_DataBound(object sender, EventArgs e)
	{
		if (Grv.PageIndex == 0)
		{
			LBtnForward.Enabled = false;
		}
		else
		{
			LBtnForward.Enabled = true;
		}

		if (Grv.PageIndex == Grv.PageCount - 1)
		{
			LBtnNext.Enabled = false;
		}
		else
		{
			LBtnNext.Enabled = true;
		}
	}

	void LBtnLast_Click(object sender, EventArgs e)
	{
		Grv.PageIndex = Grv.PageCount - 1;
		BindControls();
	}

	void LBtnNext_Click(object sender, EventArgs e)
	{
		Grv.PageIndex = Grv.PageIndex + 1;
		BindControls();
	}

	void LBtnForward_Click(object sender, EventArgs e)
	{
		Grv.PageIndex = Grv.PageIndex - 1;
		BindControls();
	}

	void LBtnFirst_Click(object sender, EventArgs e)
	{
		Grv.PageIndex = 0;
		BindControls();
	}

	/// <summary>
	/// 绑定所有控件数据
	/// </summary>
	/// <![CDATA[2014-7-23 17:00:09]]>
	private void BindControls()
	{
		BindGridView();
	}
	/// <summary>
	/// 绑定GridView控件数据
	/// </summary>
	/// <![CDATA[2014-7-23 17:02:34]]>
	private void BindGridView()
	{
		listQuestions = clsQuestionComp.QueryAll();

		Grv.DataSource = listQuestions;
		Grv.DataKeyNames = new string[] { "ID" };
		Grv.DataBind();
	}
}